<!-- HTML header for doxygen 1.8.6-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<title>OpenCV: Hit-or-Miss</title>
<link href="../../opencv.ico" rel="shortcut icon" type="image/x-icon" />
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<script type="text/javascript" src="../../tutorial-utils.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
//<![CDATA[
MathJax.Hub.Config(
{
  TeX: {
      Macros: {
          matTT: [ "\\[ \\left|\\begin{array}{ccc} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{array}\\right| \\]", 9],
          fork: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ \\end{array} \\right.", 4],
          forkthree: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ \\end{array} \\right.", 6],
          forkfour: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ #7 & \\mbox{#8}\\\\ \\end{array} \\right.", 8],
          vecthree: ["\\begin{bmatrix} #1\\\\ #2\\\\ #3 \\end{bmatrix}", 3],
          vecthreethree: ["\\begin{bmatrix} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{bmatrix}", 9],
          cameramatrix: ["#1 = \\begin{bmatrix} f_x & 0 & c_x\\\\ 0 & f_y & c_y\\\\ 0 & 0 & 1 \\end{bmatrix}", 1],
          distcoeffs: ["(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \\tau_x, \\tau_y]]]]) \\text{ of 4, 5, 8, 12 or 14 elements}"],
          distcoeffsfisheye: ["(k_1, k_2, k_3, k_4)"],
          hdotsfor: ["\\dots", 1],
          mathbbm: ["\\mathbb{#1}", 1],
          bordermatrix: ["\\matrix{#1}", 1]
      }
  }
}
);
//]]>
</script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
<link href="../../stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<!--#include virtual="/google-search.html"-->
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="../../opencv-logo-small.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">OpenCV
   &#160;<span id="projectnumber">4.5.2</span>
   </div>
   <div id="projectbrief">Open Source Computer Vision</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('../../',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="../../d9/df8/tutorial_root.html">OpenCV Tutorials</a></li><li class="navelem"><a class="el" href="../../d7/da8/tutorial_table_of_content_imgproc.html">Image Processing (imgproc module)</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Hit-or-Miss </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p><b>Prev Tutorial:</b> <a class="el" href="../../d3/dbe/tutorial_opening_closing_hats.html">More Morphology Transformations</a></p>
<p><b>Next Tutorial:</b> <a class="el" href="../../dd/dd7/tutorial_morph_lines_detection.html">Extract horizontal and vertical lines by using morphological operations</a></p>
<table class="doxtable">
<tr>
<th align="right"></th><th align="left"></th></tr>
<tr>
<td align="right">Original author </td><td align="left">Lorena García </td></tr>
<tr>
<td align="right">Compatibility </td><td align="left">OpenCV &gt;= 3.0 </td></tr>
</table>
<h2>Goal </h2>
<p>In this tutorial you will learn how to find a given configuration or pattern in a binary image by using the Hit-or-Miss transform (also known as Hit-and-Miss transform). This transform is also the basis of more advanced morphological operations such as thinning or pruning.</p>
<p>We will use the OpenCV function <b><a class="el" href="../../d4/d86/group__imgproc__filter.html#ga67493776e3ad1a3df63883829375201f" title="Performs advanced morphological transformations. ">morphologyEx()</a></b> .</p>
<h2>Hit-or-Miss theory </h2>
<p>Morphological operators process images based on their shape. These operators apply one or more <em>structuring elements</em> to an input image to obtain the output image. The two basic morphological operations are the <em>erosion</em> and the <em>dilation</em>. The combination of these two operations generate advanced morphological transformations such as <em>opening</em>, <em>closing</em>, or <em>top-hat</em> transform. To know more about these and other basic morphological operations refer to previous tutorials (<a class="el" href="../../db/df6/tutorial_erosion_dilatation.html">Eroding and Dilating</a>) and (<a class="el" href="../../d3/dbe/tutorial_opening_closing_hats.html">More Morphology Transformations</a>).</p>
<p>The Hit-or-Miss transformation is useful to find patterns in binary images. In particular, it finds those pixels whose neighbourhood matches the shape of a first structuring element \(B_1\) while not matching the shape of a second structuring element \(B_2\) at the same time. Mathematically, the operation applied to an image \(A\) can be expressed as follows: </p><p class="formulaDsp">
\[ A\circledast B = (A\ominus B_1) \cap (A^c\ominus B_2) \]
</p>
<p>Therefore, the hit-or-miss operation comprises three steps:</p><ol type="1">
<li>Erode image \(A\) with structuring element \(B_1\).</li>
<li>Erode the complement of image \(A\) ( \(A^c\)) with structuring element \(B_2\).</li>
<li>AND results from step 1 and step 2.</li>
</ol>
<p>The structuring elements \(B_1\) and \(B_2\) can be combined into a single element \(B\). Let's see an example: </p><div class="image">
<img src="../../hitmiss_kernels.png" alt="hitmiss_kernels.png"/>
<div class="caption">
Structuring elements (kernels). Left: kernel to 'hit'. Middle: kernel to 'miss'. Right: final combined kernel</div></div>
<p> In this case, we are looking for a pattern in which the central pixel belongs to the background while the north, south, east, and west pixels belong to the foreground. The rest of pixels in the neighbourhood can be of any kind, we don't care about them. Now, let's apply this kernel to an input image:</p>
<div class="image">
<img src="../../hitmiss_input.png" alt="hitmiss_input.png"/>
<div class="caption">
Input binary image</div></div>
<div class="image">
<img src="../../hitmiss_output.png" alt="hitmiss_output.png"/>
<div class="caption">
Output binary image</div></div>
<p> You can see that the pattern is found in just one location within the image.</p>
<h2>Code </h2>
<p>The code corresponding to the previous example is shown below.</p>
 <div class='newInnerHTML' title='cpp' style='display: none;'>C++</div><div class='toggleable_div label_cpp' style='display: none;'><p> You can also download it from <a href="https://raw.githubusercontent.com/opencv/opencv/master/samples/cpp/tutorial_code/ImgProc/HitMiss/HitMiss.cpp">here</a> </p><div class="fragment"><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="../../d0/d9c/core_2include_2opencv2_2core_8hpp.html">opencv2/core.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="../../d1/d4f/imgproc_2include_2opencv2_2imgproc_8hpp.html">opencv2/imgproc.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="../../d4/dd5/highgui_8hpp.html">opencv2/highgui.hpp</a>&gt;</span></div><div class="line"></div><div class="line"><span class="keyword">using namespace </span><a class="code" href="../../d2/d75/namespacecv.html">cv</a>;</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main(){</div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> input_image = (<a class="code" href="../../df/dfc/classcv_1_1Mat__.html">Mat_&lt;uchar&gt;</a>(8, 8) &lt;&lt;</div><div class="line">        0, 0, 0, 0, 0, 0, 0, 0,</div><div class="line">        0, 255, 255, 255, 0, 0, 0, 255,</div><div class="line">        0, 255, 255, 255, 0, 0, 0, 0,</div><div class="line">        0, 255, 255, 255, 0, 255, 0, 0,</div><div class="line">        0, 0, 255, 0, 0, 0, 0, 0,</div><div class="line">        0, 0, 255, 0, 0, 255, 255, 0,</div><div class="line">        0, 255, 0, 255, 0, 0, 255, 0,</div><div class="line">        0, 255, 255, 255, 0, 0, 0, 0);</div><div class="line"></div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> kernel = (<a class="code" href="../../df/dfc/classcv_1_1Mat__.html">Mat_&lt;int&gt;</a>(3, 3) &lt;&lt;</div><div class="line">        0, 1, 0,</div><div class="line">        1, -1, 1,</div><div class="line">        0, 1, 0);</div><div class="line"></div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> output_image;</div><div class="line">    <a class="code" href="../../d4/d86/group__imgproc__filter.html#ga67493776e3ad1a3df63883829375201f">morphologyEx</a>(input_image, output_image, <a class="code" href="../../d4/d86/group__imgproc__filter.html#gga7be549266bad7b2e6a04db49827f9f32acf55ff766595ec0174ba42852f0ac264">MORPH_HITMISS</a>, kernel);</div><div class="line"></div><div class="line">    <span class="keyword">const</span> <span class="keywordtype">int</span> rate = 50;</div><div class="line">    kernel = (kernel + 1) * 127;</div><div class="line">    kernel.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#adf88c60c5b4980e05bb556080916978b">convertTo</a>(kernel, <a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga32b18d904ee2b1731a9416a8eef67d06">CV_8U</a>);</div><div class="line"></div><div class="line">    <a class="code" href="../../da/d54/group__imgproc__transform.html#ga47a974309e9102f5f08231edc7e7529d">resize</a>(kernel, kernel, <a class="code" href="../../dc/d84/group__core__basic.html#ga346f563897249351a34549137c8532a0">Size</a>(), rate, rate, <a class="code" href="../../da/d54/group__imgproc__transform.html#gga5bb5a1fea74ea38e1a5445ca803ff121aa5521d8e080972c762467c45f3b70e6c">INTER_NEAREST</a>);</div><div class="line">    <a class="code" href="../../d7/dfc/group__highgui.html#ga453d42fe4cb60e5723281a89973ee563">imshow</a>(<span class="stringliteral">&quot;kernel&quot;</span>, kernel);</div><div class="line">    <a class="code" href="../../d7/dfc/group__highgui.html#ga8d86b207f7211250dbe6e28f76307ffb">moveWindow</a>(<span class="stringliteral">&quot;kernel&quot;</span>, 0, 0);</div><div class="line"></div><div class="line">    <a class="code" href="../../da/d54/group__imgproc__transform.html#ga47a974309e9102f5f08231edc7e7529d">resize</a>(input_image, input_image, <a class="code" href="../../dc/d84/group__core__basic.html#ga346f563897249351a34549137c8532a0">Size</a>(), rate, rate, <a class="code" href="../../da/d54/group__imgproc__transform.html#gga5bb5a1fea74ea38e1a5445ca803ff121aa5521d8e080972c762467c45f3b70e6c">INTER_NEAREST</a>);</div><div class="line">    <a class="code" href="../../d7/dfc/group__highgui.html#ga453d42fe4cb60e5723281a89973ee563">imshow</a>(<span class="stringliteral">&quot;Original&quot;</span>, input_image);</div><div class="line">    <a class="code" href="../../d7/dfc/group__highgui.html#ga8d86b207f7211250dbe6e28f76307ffb">moveWindow</a>(<span class="stringliteral">&quot;Original&quot;</span>, 0, 200);</div><div class="line"></div><div class="line">    <a class="code" href="../../da/d54/group__imgproc__transform.html#ga47a974309e9102f5f08231edc7e7529d">resize</a>(output_image, output_image, <a class="code" href="../../dc/d84/group__core__basic.html#ga346f563897249351a34549137c8532a0">Size</a>(), rate, rate, <a class="code" href="../../da/d54/group__imgproc__transform.html#gga5bb5a1fea74ea38e1a5445ca803ff121aa5521d8e080972c762467c45f3b70e6c">INTER_NEAREST</a>);</div><div class="line">    <a class="code" href="../../d7/dfc/group__highgui.html#ga453d42fe4cb60e5723281a89973ee563">imshow</a>(<span class="stringliteral">&quot;Hit or Miss&quot;</span>, output_image);</div><div class="line">    <a class="code" href="../../d7/dfc/group__highgui.html#ga8d86b207f7211250dbe6e28f76307ffb">moveWindow</a>(<span class="stringliteral">&quot;Hit or Miss&quot;</span>, 500, 200);</div><div class="line"></div><div class="line">    <a class="code" href="../../d7/dfc/group__highgui.html#ga5628525ad33f52eab17feebcfba38bd7">waitKey</a>(0);</div><div class="line">    <span class="keywordflow">return</span> 0;</div><div class="line">}</div></div><!-- fragment -->  </div>  <div class='newInnerHTML' title='java' style='display: none;'>Java</div><div class='toggleable_div label_java' style='display: none;'><p> You can also download it from <a href="https://raw.githubusercontent.com/opencv/opencv/master/samples/java/tutorial_code/ImgProc/HitMiss/HitMiss.java">here</a> </p><div class="fragment"><div class="line"><span class="keyword">import</span> org.opencv.core.*;</div><div class="line"><span class="keyword">import</span> org.opencv.highgui.HighGui;</div><div class="line"><span class="keyword">import</span> org.opencv.imgproc.Imgproc;</div><div class="line"></div><div class="line"><span class="keyword">class </span>HitMissRun{</div><div class="line"></div><div class="line">    <span class="keyword">public</span> <span class="keywordtype">void</span> run() {</div><div class="line">        Mat input_image = <span class="keyword">new</span> Mat( 8, 8, CvType.CV_8UC1 );</div><div class="line">        <span class="keywordtype">int</span> row = 0, col = 0;</div><div class="line">        input_image.put(row ,col,</div><div class="line">                0, 0, 0, 0, 0, 0, 0, 0,</div><div class="line">                0, 255, 255, 255, 0, 0, 0, 255,</div><div class="line">                0, 255, 255, 255, 0, 0, 0, 0,</div><div class="line">                0, 255, 255, 255, 0, 255, 0, 0,</div><div class="line">                0, 0, 255, 0, 0, 0, 0, 0,</div><div class="line">                0, 0, 255, 0, 0, 255, 255, 0,</div><div class="line">                0, 255, 0, 255, 0, 0, 255, 0,</div><div class="line">                0, 255, 255, 255, 0, 0, 0, 0);</div><div class="line"></div><div class="line">        Mat kernel = <span class="keyword">new</span> Mat( 3, 3, CvType.CV_16S );</div><div class="line">        kernel.put(row ,col,</div><div class="line">                0, 1, 0,</div><div class="line">                1, -1, 1,</div><div class="line">                0, 1, 0 );</div><div class="line"></div><div class="line">        Mat output_image = <span class="keyword">new</span> Mat();</div><div class="line">        Imgproc.morphologyEx(input_image, output_image, Imgproc.MORPH_HITMISS, kernel);</div><div class="line"></div><div class="line">        <span class="keywordtype">int</span> rate = 50;</div><div class="line">        Core.add(kernel, <span class="keyword">new</span> <a class="code" href="../../dc/d84/group__core__basic.html#ga599fe92e910c027be274233eccad7beb">Scalar</a>(1), kernel);</div><div class="line">        Core.multiply(kernel, <span class="keyword">new</span> <a class="code" href="../../dc/d84/group__core__basic.html#ga599fe92e910c027be274233eccad7beb">Scalar</a>(127), kernel);</div><div class="line">        kernel.convertTo(kernel, CvType.CV_8U);</div><div class="line"></div><div class="line">        Imgproc.resize(kernel, kernel, <span class="keyword">new</span> <a class="code" href="../../dc/d84/group__core__basic.html#ga346f563897249351a34549137c8532a0">Size</a>(), rate, rate, Imgproc.INTER_NEAREST);</div><div class="line">        HighGui.imshow(<span class="stringliteral">&quot;kernel&quot;</span>, kernel);</div><div class="line">        HighGui.moveWindow(<span class="stringliteral">&quot;kernel&quot;</span>, 0, 0);</div><div class="line"></div><div class="line">        Imgproc.resize(input_image, input_image, <span class="keyword">new</span> <a class="code" href="../../dc/d84/group__core__basic.html#ga346f563897249351a34549137c8532a0">Size</a>(), rate, rate, Imgproc.INTER_NEAREST);</div><div class="line">        HighGui.imshow(<span class="stringliteral">&quot;Original&quot;</span>, input_image);</div><div class="line">        HighGui.moveWindow(<span class="stringliteral">&quot;Original&quot;</span>, 0, 200);</div><div class="line"></div><div class="line">        Imgproc.resize(output_image, output_image, <span class="keyword">new</span> <a class="code" href="../../dc/d84/group__core__basic.html#ga346f563897249351a34549137c8532a0">Size</a>(), rate, rate, Imgproc.INTER_NEAREST);</div><div class="line">        HighGui.imshow(<span class="stringliteral">&quot;Hit or Miss&quot;</span>, output_image);</div><div class="line">        HighGui.moveWindow(<span class="stringliteral">&quot;Hit or Miss&quot;</span>, 500, 200);</div><div class="line"></div><div class="line">        HighGui.waitKey(0);</div><div class="line">        System.exit(0);</div><div class="line">    }</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">public</span> <span class="keyword">class </span>HitMiss</div><div class="line">{</div><div class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keywordtype">void</span> main(<a class="code" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a>[] args) {</div><div class="line">        <span class="comment">// load the native OpenCV library</span></div><div class="line">        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);</div><div class="line">        <span class="keyword">new</span> HitMissRun().run();</div><div class="line">    }</div><div class="line">}</div></div><!-- fragment -->  </div>  <div class='newInnerHTML' title='python' style='display: none;'>Python</div><div class='toggleable_div label_python' style='display: none;'><p> You can also download it from <a href="https://raw.githubusercontent.com/opencv/opencv/master/samples/python/tutorial_code/imgProc/HitMiss/hit_miss.py">here</a> </p><div class="fragment"><div class="line"><span class="keyword">import</span> cv2 <span class="keyword">as</span> cv</div><div class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</div><div class="line"></div><div class="line">input_image = np.array((</div><div class="line">    [0, 0, 0, 0, 0, 0, 0, 0],</div><div class="line">    [0, 255, 255, 255, 0, 0, 0, 255],</div><div class="line">    [0, 255, 255, 255, 0, 0, 0, 0],</div><div class="line">    [0, 255, 255, 255, 0, 255, 0, 0],</div><div class="line">    [0, 0, 255, 0, 0, 0, 0, 0],</div><div class="line">    [0, 0, 255, 0, 0, 255, 255, 0],</div><div class="line">    [0,255, 0, 255, 0, 0, 255, 0],</div><div class="line">    [0, 255, 255, 255, 0, 0, 0, 0]), dtype=<span class="stringliteral">&quot;uint8&quot;</span>)</div><div class="line"></div><div class="line">kernel = np.array((</div><div class="line">        [0, 1, 0],</div><div class="line">        [1, -1, 1],</div><div class="line">        [0, 1, 0]), dtype=<span class="stringliteral">&quot;int&quot;</span>)</div><div class="line"></div><div class="line">output_image = <a class="code" href="../../d4/d86/group__imgproc__filter.html#ga67493776e3ad1a3df63883829375201f">cv.morphologyEx</a>(input_image, cv.MORPH_HITMISS, kernel)</div><div class="line"></div><div class="line">rate = 50</div><div class="line">kernel = (kernel + 1) * 127</div><div class="line">kernel = np.uint8(kernel)</div><div class="line"></div><div class="line">kernel = <a class="code" href="../../da/d54/group__imgproc__transform.html#ga47a974309e9102f5f08231edc7e7529d">cv.resize</a>(kernel, <span class="keywordtype">None</span>, fx = rate, fy = rate, interpolation = cv.INTER_NEAREST)</div><div class="line"><a class="code" href="../../df/d24/group__highgui__opengl.html#gaae7e90aa3415c68dba22a5ff2cefc25d">cv.imshow</a>(<span class="stringliteral">&quot;kernel&quot;</span>, kernel)</div><div class="line"><a class="code" href="../../d7/dfc/group__highgui.html#ga8d86b207f7211250dbe6e28f76307ffb">cv.moveWindow</a>(<span class="stringliteral">&quot;kernel&quot;</span>, 0, 0)</div><div class="line"></div><div class="line">input_image = <a class="code" href="../../da/d54/group__imgproc__transform.html#ga47a974309e9102f5f08231edc7e7529d">cv.resize</a>(input_image, <span class="keywordtype">None</span>, fx = rate, fy = rate, interpolation = cv.INTER_NEAREST)</div><div class="line"><a class="code" href="../../df/d24/group__highgui__opengl.html#gaae7e90aa3415c68dba22a5ff2cefc25d">cv.imshow</a>(<span class="stringliteral">&quot;Original&quot;</span>, input_image)</div><div class="line"><a class="code" href="../../d7/dfc/group__highgui.html#ga8d86b207f7211250dbe6e28f76307ffb">cv.moveWindow</a>(<span class="stringliteral">&quot;Original&quot;</span>, 0, 200)</div><div class="line"></div><div class="line">output_image = <a class="code" href="../../da/d54/group__imgproc__transform.html#ga47a974309e9102f5f08231edc7e7529d">cv.resize</a>(output_image, <span class="keywordtype">None</span> , fx = rate, fy = rate, interpolation = cv.INTER_NEAREST)</div><div class="line"><a class="code" href="../../df/d24/group__highgui__opengl.html#gaae7e90aa3415c68dba22a5ff2cefc25d">cv.imshow</a>(<span class="stringliteral">&quot;Hit or Miss&quot;</span>, output_image)</div><div class="line"><a class="code" href="../../d7/dfc/group__highgui.html#ga8d86b207f7211250dbe6e28f76307ffb">cv.moveWindow</a>(<span class="stringliteral">&quot;Hit or Miss&quot;</span>, 500, 200)</div><div class="line"></div><div class="line"><a class="code" href="../../d7/dfc/group__highgui.html#ga5628525ad33f52eab17feebcfba38bd7">cv.waitKey</a>(0)</div><div class="line"><a class="code" href="../../d7/dfc/group__highgui.html#ga6b7fc1c1a8960438156912027b38f481">cv.destroyAllWindows</a>()</div></div><!-- fragment -->  </div> <p>As you can see, it is as simple as using the function <b><a class="el" href="../../d4/d86/group__imgproc__filter.html#ga67493776e3ad1a3df63883829375201f" title="Performs advanced morphological transformations. ">morphologyEx()</a></b> with the operation type <b>MORPH_HITMISS</b> and the chosen kernel.</p>
<h2>Other examples </h2>
<p>Here you can find the output results of applying different kernels to the same input image used before:</p>
<div class="image">
<img src="../../hitmiss_example2.png" alt="hitmiss_example2.png"/>
<div class="caption">
Kernel and output result for finding top-right corners</div></div>
<div class="image">
<img src="../../hitmiss_example3.png" alt="hitmiss_example3.png"/>
<div class="caption">
Kernel and output result for finding left end points</div></div>
<p> Now try your own patterns! </p>
</div></div><!-- contents -->
<!-- HTML footer for doxygen 1.8.6-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Fri Apr 2 2021 11:36:35 for OpenCV by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="../../doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
<script type="text/javascript">
//<![CDATA[
addTutorialsButtons();
//]]>
</script>
</body>
</html>
